import { http } from '@/utils/http.ts'
import type { HomeBanner, HomeCategory, HomeGuess, HomeHot } from '@/types/home'
import type { PageParams, PageResult } from '@/types/global'

export const getHomeBannerApi = (distributionSite = 1) => {
  return http<HomeBanner[]>({
    method: 'GET',
    url: '/home/banner',
    data: {
      distributionSite,
    },
  })
}

export const getHomeCategoryApi = () => {
  return http<HomeCategory[]>({
    method: 'GET',
    url: '/home/category/mutli',
  })
}

export const getHomeHotApi = () => {
  return http<HomeHot[]>({
    method: 'GET',
    url: '/home/hot/mutli',
  })
}

// data?: PageParams 是请求携带的参数，http<PageResult<HomeGuess[]>> 是响应返回的数据类型
export const getHomeGoodsApi = (data?: PageParams) => {
  return http<PageResult<HomeGuess[]>>({
    method: 'GET',
    url: '/home/goods/guessLike',
    data,
  })
}

import type { HotItem, HotParams } from '@/types/home'

// 此时 data 可以不传，并且 data 内部都是可选参数，可以只传递要的参数
export const getHotDataApi = (url: string, data?: HotParams) => {
  return http<HotItem>({
    method: 'GET',
    url,
    data,
  })
}
